<template>
	<div>
		<van-panel title="个人版微盘登录" style="margin-top: 50%;">
			<van-field v-model="key" placeholder="请输入密钥" style="width: 90%;margin-left: 5%;" />
			<van-button type="info" style="width: 90%; margin-left: 5%;margin-bottom: 5%;" @click="login()">进入网盘
			</van-button>
		</van-panel>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				key: "",

				title: 'login',
			}
		},
		mounted() {
			const key = localStorage.getItem("key")
			if (key != undefined && key != '') {
				this.$router.push('/home')
			}
		},
		methods: {
			login() {
				this.$http.post('/login', {
					key: this.key
				}).then(res => {
					if (res.data.code == 0) {
						localStorage.setItem('key', res.data.data)
						const _this = this
						this.$toast({
							type: 'success',
							message: '验证成功',
							onClose: function() {
								_this.$router.push('/home')
							},
							duration: 1000
						});
					} else {
						this.$toast({
							type: 'fail',
							message: res.data.msg
						});
					}

				})

			}
		}

	}
</script>

<style>
</style>
